home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / stsbar.zip / SBTEST.C < prev    next >
Text File  |  1991-09-12  |  16KB  |  454 lines

  1. //===========================================================================
  2. //  Program          : SBTEST.C
  3. //  Version          : 1.0
  4. //  Operating System : DOS / Windows 3.0
  5. //  Author           : Jean-Marc Krikorian
  6. //                     525 Sandy Lane 
  7. //                     Libertyville, IL  60048 
  8. //                     (708) 816-3314 
  9. // 
  10. //  Copyright 1991 Jean-Marc Krikorian. All Rights Reserved.
  11. // 
  12. //===========================================================================
  13.  
  14. #include "windows.h"  
  15. #include "sbtest.h"  
  16. #include "stsbar.ext"
  17.  
  18. #define ID_STATUSBAR 2000
  19.  
  20. HANDLE hInst;
  21. HWND   hWndStatusBar = 0;
  22. HMENU  hMenu = 0;
  23. WORD   wTextAttributes = 0;
  24. WORD   wCurrentFaceColor = 0;
  25. WORD   wCurrentFaceStyle = 0;
  26. WORD   wCurrentTextColor = 0;
  27. WORD   wCurrentTextFont = 0;
  28. BOOL   bStatusBarVisible = FALSE;
  29. WORD   ypos = 0;
  30.  
  31.  
  32. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  33. {
  34.   MSG msg;                  
  35.  
  36.   if (!hPrevInstance)            
  37.       if (!InitApplication(hInstance)) 
  38.         return (FALSE);        
  39.  
  40.   if (!InitInstance(hInstance, nCmdShow))
  41.       return (FALSE);
  42.  
  43.   while (GetMessage(&msg, NULL, NULL,    NULL)) 
  44.   {
  45.       TranslateMessage(&msg);    
  46.       DispatchMessage(&msg);    
  47.   }
  48.  
  49.   return (msg.wParam);    
  50. }
  51.  
  52. BOOL InitApplication(HANDLE hInstance)
  53. {
  54.   WNDCLASS  wc;
  55.  
  56.   wc.style = NULL;                 
  57.   wc.lpfnWndProc = MainWndProc;    
  58.                                    
  59.   wc.cbClsExtra = 0;               
  60.   wc.cbWndExtra = 0;               
  61.   wc.hInstance = hInstance;        
  62.   wc.hIcon = LoadIcon(hInstance, "SBTestIcon");
  63.   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  64.   wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  65.   wc.lpszMenuName =  "SBTestMenu";   
  66.   wc.lpszClassName = "SBTestWClass"; 
  67.  
  68.   return (RegisterClass(&wc));
  69. }
  70.  
  71. BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  72. {
  73.   HWND   hWnd;
  74.   HANDLE hStatusBarFont;
  75.   HFONT  hFont;
  76.   LONG   lMyLong;
  77.   WORD   wSize;
  78.  
  79.   hInst = hInstance;
  80.  
  81.   hWnd = CreateWindow("SBTestWClass",                
  82.                       "Status Bar Test Application",   
  83.                       WS_OVERLAPPEDWINDOW,            
  84.                       CW_USEDEFAULT,                  
  85.                       CW_USEDEFAULT,                  
  86.                       CW_USEDEFAULT,                  
  87.                       CW_USEDEFAULT,                  
  88.                       NULL,                           
  89.                       NULL,                           
  90.                       hInstance,                      
  91.                       NULL);
  92.  
  93.   if (!hWnd)
  94.     return (FALSE);
  95.  
  96.   // init Status Bar
  97.   StatusBarInit(hInst);
  98.  
  99.   ypos = 10;
  100.  
  101.   // Create the status bar window
  102.   hWndStatusBar = CreateWindow("StatusBarClass",
  103.                                NULL,
  104.                                WS_CHILD | SBS_MOVEABLE,
  105.                                0,ypos,0,0,
  106.                                hWnd,
  107.                                ID_STATUSBAR,
  108.                                hInst,
  109.                                NULL);
  110.  
  111.   if (!hWndStatusBar)
  112.   {
  113.     MessageBox(hWnd, "No Status Bar", "FUCK!!!!", MB_OK);
  114.     return (FALSE);
  115.   }
  116.  
  117.   SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_3DFACE);
  118.   wCurrentFaceStyle = IDM_SB3DFACE;
  119.   CheckMenuItem(hMenu, wCurrentFaceStyle, MF_CHECKED);
  120.  
  121.   SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GRAY);
  122.   wCurrentFaceColor = IDM_SBGRAYFACE;
  123.   CheckMenuItem(hMenu, wCurrentFaceColor, MF_CHECKED);
  124.  
  125.   SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_BLACK);
  126.   wCurrentTextColor = IDM_SBBLACKTEXT;
  127.   CheckMenuItem(hMenu, wCurrentTextColor, MF_CHECKED);
  128.  
  129.   wCurrentTextFont = IDM_SBDEFAULTSYSTEM;
  130.   CheckMenuItem(hMenu, wCurrentTextFont, MF_CHECKED);
  131.  
  132.   bStatusBarVisible = TRUE;
  133.   CheckMenuItem(hMenu, IDM_SBSHOW, MF_CHECKED);
  134.  
  135.   ShowWindow(hWndStatusBar, SW_SHOW);
  136.  
  137.   ShowWindow(hWnd, nCmdShow);  
  138.   UpdateWindow(hWnd);          
  139.  
  140.   return (TRUE);    
  141. }
  142.  
  143. long FAR PASCAL MainWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
  144. {
  145.   static char    SText[80];
  146.          LOGFONT lf;
  147.  
  148.   switch (message)
  149.   {
  150.     case WM_CREATE:
  151.       hMenu = GetMenu(hWnd);
  152.       wsprintf(SText, "%s%d", (LPSTR)"This is the Status Bar...", GetWindowWord(hWnd, GWW_HINSTANCE));
  153.       return 0;
  154.  
  155.       case WM_COMMAND:
  156.     {
  157.       switch (wParam)
  158.       {
  159.           case IDM_SBSHOW:
  160.           bStatusBarVisible = TRUE;
  161.           CheckMenuItem(hMenu, IDM_SBSHOW, MF_CHECKED);
  162.           CheckMenuItem(hMenu, IDM_SBHIDE, MF_UNCHECKED);
  163.           ShowWindow(hWndStatusBar, SW_SHOW);
  164.           return 0;
  165.  
  166.         case IDM_SBHIDE:
  167.           bStatusBarVisible = FALSE;
  168.           CheckMenuItem(hMenu, IDM_SBHIDE, MF_CHECKED);
  169.           CheckMenuItem(hMenu, IDM_SBSHOW, MF_UNCHECKED);
  170.           ShowWindow(hWndStatusBar, SW_HIDE);
  171.           return 0;
  172.  
  173.         case IDM_SBDISPLAYTEXT:
  174.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, 0, (LONG)(LPSTR)SText);
  175.               return 0;
  176.  
  177.           case IDM_SB3DFACE:
  178.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  179.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  180.           wCurrentFaceStyle = wParam;
  181.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_3DFACE);
  182.           return 0;
  183.  
  184.           case IDM_SB2DFACE:
  185.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  186.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  187.           wCurrentFaceStyle = wParam;
  188.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_2DFACE);
  189.           return 0;
  190.  
  191.           case IDM_SBFLATFACE:
  192.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  193.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  194.           wCurrentFaceStyle = wParam;
  195.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_FLATFACE);
  196.           return 0;
  197.  
  198.           case IDM_SBGRAYFACE:
  199.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  200.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  201.           wCurrentFaceColor = wParam;
  202.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GRAY);
  203.           return 0;
  204.  
  205.           case IDM_SBBLACKFACE:
  206.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  207.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  208.           wCurrentFaceColor = wParam;
  209.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_BLACK);
  210.           return 0;
  211.  
  212.           case IDM_SBWHITEFACE:
  213.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  214.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  215.           wCurrentFaceColor = wParam;
  216.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_WHITE);
  217.           return 0;
  218.  
  219.           case IDM_SBREDFACE:
  220.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  221.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  222.           wCurrentFaceColor = wParam;
  223.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_RED);
  224.           return 0;
  225.  
  226.           case IDM_SBGREENFACE:
  227.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  228.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  229.           wCurrentFaceColor = wParam;
  230.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GREEN);
  231.           return 0;
  232.  
  233.           case IDM_SBBLUEFACE:
  234.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  235.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  236.           wCurrentFaceColor = wParam;
  237.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_BLUE);
  238.           return 0;
  239.  
  240.         case IDM_SBHELV8:
  241.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  242.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  243.           wCurrentTextFont = wParam;
  244.           lf.lfHeight = 8;
  245.           lf.lfWidth = 0;          // this field is ignored
  246.           lf.lfEscapement = 0;     // this field is ignored
  247.           lf.lfOrientation = 0;    // this field is ignored
  248.           lf.lfWeight = 0;         // this field is ignored
  249.           lf.lfItalic = 0;         // this field is ignored
  250.           lf.lfUnderline = 0;      // this field is ignored
  251.           lf.lfStrikeOut = 0;      // this field is ignored
  252.           lf.lfCharSet = 0;        // this field is ignored
  253.           lf.lfOutPrecision = 0;   // this field is ignored
  254.           lf.lfClipPrecision = 0;  // this field is ignored
  255.           lf.lfQuality = 0;        // this field is ignored
  256.           lf.lfPitchAndFamily = 0; // this field is ignored
  257.           lstrcpy (lf.lfFaceName, "Helv");
  258.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, (LONG)(LPLOGFONT)&lf);
  259.           return 0;
  260.  
  261.         case IDM_SBARIAL25:
  262.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  263.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  264.           wCurrentTextFont = wParam;
  265.           lf.lfHeight = 25;
  266.           lf.lfWidth = 0;          // this field is ignored
  267.           lf.lfEscapement = 0;     // this field is ignored
  268.           lf.lfOrientation = 0;    // this field is ignored
  269.           lf.lfWeight = 0;         // this field is ignored
  270.           lf.lfItalic = 0;         // this field is ignored
  271.           lf.lfUnderline = 0;      // this field is ignored
  272.           lf.lfStrikeOut = 0;      // this field is ignored
  273.           lf.lfCharSet = 0;        // this field is ignored
  274.           lf.lfOutPrecision = 0;   // this field is ignored
  275.           lf.lfClipPrecision = 0;  // this field is ignored
  276.           lf.lfQuality = 0;        // this field is ignored
  277.           lf.lfPitchAndFamily = 0; // this field is ignored
  278.           lstrcpy (lf.lfFaceName, "Arial");
  279.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, (LONG)(LPLOGFONT)&lf);
  280.           return 0;
  281.  
  282.         case IDM_SBTMS12:
  283.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  284.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  285.           wCurrentTextFont = wParam;
  286.           lf.lfHeight = 12;
  287.           lf.lfWidth = 0;          // this field is ignored
  288.           lf.lfEscapement = 0;     // this field is ignored
  289.           lf.lfOrientation = 0;    // this field is ignored
  290.           lf.lfWeight = 0;         // this field is ignored
  291.           lf.lfItalic = 0;         // this field is ignored
  292.           lf.lfUnderline = 0;      // this field is ignored
  293.           lf.lfStrikeOut = 0;      // this field is ignored
  294.           lf.lfCharSet = 0;        // this field is ignored
  295.           lf.lfOutPrecision = 0;   // this field is ignored
  296.           lf.lfClipPrecision = 0;  // this field is ignored
  297.           lf.lfQuality = 0;        // this field is ignored
  298.           lf.lfPitchAndFamily = 0; // this field is ignored
  299.           lstrcpy (lf.lfFaceName, "Tms");
  300.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, (LONG)(LPLOGFONT)&lf);
  301.           return 0;
  302.  
  303.         case IDM_SBDEFAULTSYSTEM:
  304.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  305.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  306.           wCurrentTextFont = wParam;
  307.           SendMessage(hWndStatusBar, SBM_SETFONT, ypos, 0L);
  308.           return 0;
  309.  
  310.           case IDM_SBGRAYTEXT:
  311.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  312.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  313.           wCurrentTextColor = wParam;
  314.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_GRAY);
  315.           return 0;
  316.  
  317.           case IDM_SBBLACKTEXT:
  318.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  319.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  320.           wCurrentTextColor = wParam;
  321.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_BLACK);
  322.           return 0;
  323.  
  324.           case IDM_SBWHITETEXT:
  325.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  326.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  327.           wCurrentTextColor = wParam;
  328.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_WHITE);
  329.           return 0;
  330.  
  331.           case IDM_SBREDTEXT:
  332.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  333.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  334.           wCurrentTextColor = wParam;
  335.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_RED);
  336.           return 0;
  337.  
  338.           case IDM_SBGREENTEXT:
  339.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  340.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  341.           wCurrentTextColor = wParam;
  342.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_GREEN);
  343.           return 0;
  344.  
  345.           case IDM_SBBLUETEXT:
  346.           CheckMenuItem(hMenu, wCurrentTextColor, MF_UNCHECKED);
  347.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  348.           wCurrentTextColor = wParam;
  349.           SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_BLUE);
  350.           return 0;
  351.  
  352.           case IDM_SBBOLD:
  353.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  354.           {
  355.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  356.             wTextAttributes = wTextAttributes & ~SBTA_BOLD;
  357.           }
  358.           else
  359.           {
  360.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  361.             wTextAttributes = wTextAttributes | SBTA_BOLD;
  362.           }
  363.  
  364.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  365.           return 0;
  366.  
  367.           case IDM_SBITALICS:
  368.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  369.           {
  370.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  371.             wTextAttributes = wTextAttributes & ~SBTA_ITALICS;
  372.           }
  373.           else
  374.           {
  375.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  376.             wTextAttributes = wTextAttributes | SBTA_ITALICS;
  377.           }
  378.  
  379.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  380.           return 0;
  381.  
  382.           case IDM_SBUNDERLINE:
  383.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  384.           {
  385.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  386.             wTextAttributes = wTextAttributes & ~SBTA_UNDERLINE;
  387.           }
  388.           else
  389.           {
  390.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  391.             wTextAttributes = wTextAttributes | SBTA_UNDERLINE;
  392.           }
  393.  
  394.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  395.           return 0;
  396.  
  397.           case IDM_SBSTRIKEOUT:
  398.           if (GetMenuState(hMenu, wParam, MF_BYCOMMAND) == MF_CHECKED)
  399.           {
  400.             CheckMenuItem(hMenu, wParam, MF_UNCHECKED);
  401.             wTextAttributes = wTextAttributes & ~SBTA_STRIKEOUT;
  402.           }
  403.           else
  404.           {
  405.             CheckMenuItem(hMenu, wParam, MF_CHECKED);
  406.             wTextAttributes = wTextAttributes | SBTA_STRIKEOUT;
  407.           }
  408.  
  409.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  410.           return 0;
  411.  
  412.         case ID_STATUSBAR:
  413.           switch (HIWORD(lParam))
  414.           {
  415.             case SBN_LBUTTONUP:
  416.               MessageBeep(0);
  417.               return 0;
  418.  
  419.             case SBN_LBUTTONDBLCLK:
  420.               MessageBox(hWnd, "Left Mouse Button Double-Click", "Status Bar Test", MB_OK);
  421.               return 0;
  422.  
  423.             case SBN_RBUTTONUP:
  424.               MessageBeep(0);
  425.               return 0;
  426.  
  427.             case SBN_RBUTTONDBLCLK:
  428.               MessageBox(hWnd, "Right Mouse Button Double-Click", "Status Bar Test", MB_OK);
  429.               return 0;
  430.           }
  431.       }
  432.     }
  433.     return 0;
  434.  
  435.     case WM_DESTROY:
  436.       // uninit Status Bar
  437.       StatusBarUnInit(GetWindowWord(hWnd, GWW_HINSTANCE));
  438.  
  439.       PostQuitMessage(0);
  440.       return 0;
  441.  
  442.  
  443.     case WM_SIZE:
  444.       if (hWndStatusBar)
  445.       {
  446.         SendMessage(hWndStatusBar, SBM_SIZE, ypos, lParam);
  447.         ypos += 10;
  448.       }
  449.       return 0;
  450.   }
  451.  
  452.   return (DefWindowProc(hWnd, message, wParam, lParam));
  453. }
  454.